﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace H.Nets
{
    /// <summary>
    /// 传入一个新的客户端连接
    /// </summary>
    /// <param name="newClient"></param>
    public delegate void NewConnectionHandler(ITcpClient newClient);

    /// <summary>
    /// 客户端改名事件处理委托
    /// </summary>
    public delegate void ClientRenameHandler(string oldName, string newName);

    /// <summary>
    /// 表示一个网络服务服务端
    /// </summary>
    public interface ITcpServer : IDisposable
    {
        /// <summary>
        /// 当有客户端与服务器建立新连接时
        /// </summary>
        event NewConnectionHandler NewConnection;

        /// <summary>
        /// 当一个客户端改名时发射的事件
        /// </summary>
        event ClientRenameHandler ClientRename;

        /// <summary>
        /// 开始接受客户端连接请求
        /// </summary>
        void Start();

        /// <summary>
        /// 停止接受客户端连接请求
        /// </summary>
        void Stop();

        /// <summary>
        /// 将线程的所有权交给服务端的等待链接线程
        /// </summary>
        void LoopWait();

        /// <summary>
        /// 根据标识符获取客户端ID
        /// </summary>
        /// <param name="identifier">客户端ID</param>
        /// <returns>客户端ID</returns>
        ITcpClient GetClient(string identifier);

    }
}
